home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / test64k.c < prev    next >
C/C++ Source or Header  |  1993-10-21  |  8KB  |  246 lines

  1. /****************************************************************************
  2. *
  3. *                          SuperVGA Test Library
  4. *
  5. *                   Copyright (C) 1993 SciTech Software
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: test64k.c $
  9. * Version:      $Revision: 1.2 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MSDOS)
  13. *
  14. * Description:  Simple program to test the operation of the SuperVGA
  15. *               bank switching code and page flipping code for the
  16. *               64k color SuperVGA video modes.
  17. *
  18. *               MUST be compiled in the large model.
  19. *
  20. * $Id: test64k.c 1.2 1993/10/22 08:58:40 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <dos.h>
  28. #include <conio.h>
  29. #include "svga.h"
  30.  
  31. /*---------------------------- Global Variables ---------------------------*/
  32.  
  33. #include "version.c"
  34.  
  35. int     x,y;
  36.  
  37. /*----------------------------- Implementation ----------------------------*/
  38.  
  39. void moireTest(void)
  40. /****************************************************************************
  41. *
  42. * Function:     moireTest
  43. *
  44. * Description:  Draws a simple Moire pattern on the display screen using
  45. *               lines, and waits for a key press.
  46. *
  47. ****************************************************************************/
  48. {
  49.     uchar   buf[80];
  50.     int     i;
  51.     uint    value;
  52.  
  53.     clear();
  54.     for (i = 0; i < maxx; i++) {
  55.         line(maxx/2,maxy/2,i,0,rgbColor((uchar)((i*255L)/maxx),0,0));
  56.         line(maxx/2,maxy/2,i,maxy,rgbColor(0,(uchar)((i*255L)/maxx),0));
  57.         }
  58.     for (i = 0; i < maxy; i++) {
  59.         value = (i*255L)/maxy;
  60.         line(maxx/2,maxy/2,0,i,rgbColor((uchar)value,0,(uchar)(255 - value)));
  61.         line(maxx/2,maxy/2,maxx,i,rgbColor(0,(uchar)(255 - value),(uchar)value));
  62.         }
  63.     line(0,0,maxx,0,defcolor);
  64.     line(0,0,0,maxy,defcolor);
  65.     line(maxx,0,maxx,maxy,defcolor);
  66.     line(0,maxy,maxx,maxy,defcolor);
  67.  
  68.     if (maxx != 319) {
  69.         x = 80;
  70.         y = 80;
  71.         writeText(x,y,"Bank switching test",defcolor);  y += 32;
  72.         sprintf(buf,"Video mode: %d x %d 64k color",maxx+1,maxy+1);
  73.         writeText(x,y,buf,defcolor);    y += 16;
  74.         sprintf(buf,"Maximum x: %d, Maximum y: %d, BytesPerLine %d, Pages: %d",
  75.             maxx,maxy,bytesperline,maxpage+1);
  76.         writeText(x,y,buf,defcolor);    y += 32;
  77.         writeText(x,y,"You should see a smooth transition of colors on the screen",defcolor);
  78.         y += 16;
  79.         }
  80.     else {
  81.         x = 40;
  82.         y = 40;
  83.         }
  84.     writeText(x,y,"Press any key to continue",defcolor);
  85.     y += 32;
  86.     getch();
  87. }
  88.  
  89. void pageFlipTest(void)
  90. /****************************************************************************
  91. *
  92. * Function:     pageFlipTest
  93. *
  94. * Description:  Animates a line on the display using page flipping if
  95. *               page flipping is active.
  96. *
  97. ****************************************************************************/
  98. {
  99.     int     i,j,istep,jstep,color,apage,vpage;
  100.     char    buf[80];
  101.  
  102.     if (maxpage != 0) {
  103.         vpage = 0;
  104.         apage = 1;
  105.         setActivePage(apage);
  106.         setVisualPage(vpage);
  107.         i = 0;
  108.         j = maxy;
  109.         istep = 2;
  110.         jstep = -2;
  111.         color = 0xFFFF;
  112.         while (!kbhit()) {
  113.             setActivePage(apage);
  114.             clear();
  115.             sprintf(buf,"Page %d of %d", vpage+1, maxpage+1);
  116.             if (maxx == 319) {
  117.                 writeText(0,80,"Page flipping - should be no flicker",defcolor);
  118.                 writeText(0,100,buf,defcolor);
  119.                 }
  120.             else {
  121.                 writeText(80,80,"Page flipping - should be no flicker",defcolor);
  122.                 writeText(80,100,buf,defcolor);
  123.                 }
  124.             line(i,0,maxx-i,maxy,color);
  125.             line(0,maxy-j,maxx,j,color);
  126.             vpage = ++vpage % (maxpage+1);
  127.             setVisualPage(vpage);
  128.             apage = ++apage % (maxpage+1);
  129.             i += istep;
  130.             if (i > maxx) {
  131.                 i = maxx-2;
  132.                 istep = -2;
  133.                 }
  134.             if (i < 0)  i = istep = 2;
  135.             j += jstep;
  136.             if (j > maxy) {
  137.                 j = maxy-2;
  138.                 jstep = -2;
  139.                 }
  140.             if (j < 0)  j = jstep = 2;
  141.             }
  142.         getch();                /* Swallow keypress */
  143.         }
  144. }
  145.  
  146. void testingComplete(void)
  147. /****************************************************************************
  148. *
  149. * Function:     testingComplete
  150. *
  151. * Description:  Clears the first display page and puts up a message.
  152. *
  153. ****************************************************************************/
  154. {
  155.     setActivePage(0);
  156.     setVisualPage(0);
  157.     clear();
  158.  
  159.     if (maxx == 319) {
  160.         writeText(0,40,"Testing complete",defcolor);
  161.         writeText(0,60,"press any key to return to text mode",defcolor);
  162.         }
  163.     else
  164.         writeText(80,80,"Testing complete - press any key to return to text mode",defcolor);
  165.     getch();
  166. }
  167.  
  168. int queryCpu(void);
  169.  
  170. void main(void)
  171. {
  172.     int     i,choice,maxmenu;
  173.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  174.     long    pagesize;
  175.     int     menu[20];
  176.     char    buf[80];
  177.  
  178.     if (queryCpu() < 4) {
  179.         printf("This program contains '386 specific instructions, and will not work on\n");
  180.         printf("this machine - sorry\n");
  181.         }
  182.  
  183.     if (initSuperVGA() != 0x102) {
  184.         printf("This program requires a VESA VBE 1.2 compatible SuperVGA. Try installing\n");
  185.         printf("the Universal VESA VBE for your video card, or contact your video card\n");
  186.         printf("vendor and ask for a suitable TSR\n");
  187.         exit(1);
  188.         }
  189.  
  190.     while (true) {
  191. #ifdef  __TURBOC__
  192.         clrscr();
  193. #endif
  194.         printf("65,536 color SuperVGA test program (Version %s)\n\n",version);
  195.         printf("VBE OEM string: %s\n",OEMString);
  196.         printf("Memory:         %dk\n",memory);
  197.         printf("\n");
  198.         printf("Separate read/write banks: %s\n", twobanks ? "Yes" : "No");
  199.         printf("Extended page flipping:    %s\n", extendedflipping ? "Yes" : "No");
  200.         printf("\n");
  201.         printf("Which video mode to test:\n\n");
  202.  
  203.         maxmenu = 0;
  204.         for (i = 0; modeList[i] != -1; i++) {
  205.             /* Filter out the 64k color video modes */
  206.  
  207.             if (modeList[i] < 0x100)
  208.                 continue;
  209.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  210.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  211.                 continue;
  212.             if (bitsperpixel == 16) {
  213.                 printf("    [%2d] - %d x %d 65,536 color (%d page)\n",maxmenu,
  214.                     xres,yres,maxpage+1);
  215.                 menu[maxmenu++] = modeList[i];
  216.                 }
  217.             }
  218.         if (maxmenu == 0) {
  219.             printf("No modes available...\n");
  220.             exit(1);
  221.             }
  222.         printf("    [ Q] - Quit\n\n");
  223.         printf("Choice: ");
  224.  
  225.         gets(buf);
  226.         if (buf[0] == 'q' || buf[0] == 'Q')
  227.             break;
  228.  
  229.         choice = atoi(buf);
  230.         if (0 <= choice && choice < maxmenu) {
  231.             if (!setSuperVGAMode(menu[choice])) {
  232.                 printf("\n");
  233.                 printf("ERROR: Video mode did not set correctly!\n\n");
  234.                 printf("\nPress any key to continue...\n");
  235.                 getch();
  236.                 }
  237.             else {
  238.                 moireTest();
  239.                 pageFlipTest();
  240.                 testingComplete();
  241.                 restoreMode();
  242.                 }
  243.             }
  244.         }
  245. }
  246.